﻿using System.Configuration;
using System.IO;
using System.Reflection;

namespace bitMail.Class
{
    public class ConfigHelper
    {
        public string AppPath { get; set; }

        public ConfigHelper()
        {
            AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        }
        public string ActualExcelPath
        {
            get
            {
                return ConfigurationManager.AppSettings["ExcelPlik"];
            }
        }

        public void PodmienUstawieniaSciezkiExcela(string value)
        {
            if (string.IsNullOrEmpty(AppPath)) return;
            var configFile = Path.Combine(AppPath, "bitMail.exe.config");
            var configFileMap = new ExeConfigurationFileMap
            {
                ExeConfigFilename = configFile
            };
            var config = ConfigurationManager
                .OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            config.AppSettings.Settings["ExcelPlik"].Value = value;
            config.Save();
        }

        public void PodmienUstawieniaSciezkiOutlook(string value)
        {
            if (string.IsNullOrEmpty(AppPath)) return;
            var configFile = Path.Combine(AppPath, "bitMail.exe.config");
            var configFileMap = new ExeConfigurationFileMap
            {
                ExeConfigFilename = configFile
            };           
            var config = ConfigurationManager
                .OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            config.AppSettings.Settings["OutlookPlik"].Value = value;
            config.Save();
        }
    }
}
